home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Graphics 3D / SetupGL / Error Handler.c next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  6.7 KB  |  209 lines  |  [TEXT/CWIE]

  1. /*
  2.     File:        Error Handler.c
  3.  
  4.     Contains:    SetupGL error handling
  5.  
  6.     Written by:    Geoff Stahl (ggs)
  7.  
  8.     Copyright:    Copyright © 1999 Apple Computer, Inc., All Rights Reserved
  9.  
  10.     Change History (most recent first):
  11.  
  12.          <4>     1/24/00    ggs     double check for latest
  13.          <4>     1/24/00    ggs     double check for latest
  14.          <3>    12/18/99    ggs     Fix headers
  15.          <2>    11/28/99    ggs     Added verbose error flag
  16.          <1>    11/28/99    ggs     Initial add.  Split of just error handling functions.  Need to
  17.                                     add more reporting examples
  18.          <1>    11/11/99    ggs     Initial Add
  19.  
  20.     Disclaimer:    IMPORTANT:  This Apple software is supplied to you by Apple Computer, Inc.
  21.                 ("Apple") in consideration of your agreement to the following terms, and your
  22.                 use, installation, modification or redistribution of this Apple software
  23.                 constitutes acceptance of these terms.  If you do not agree with these terms,
  24.                 please do not use, install, modify or redistribute this Apple software.
  25.  
  26.                 In consideration of your agreement to abide by the following terms, and subject
  27.                 to these terms, Apple grants you a personal, non-exclusive license, under Apple’s
  28.                 copyrights in this original Apple software (the "Apple Software"), to use,
  29.                 reproduce, modify and redistribute the Apple Software, with or without
  30.                 modifications, in source and/or binary forms; provided that if you redistribute
  31.                 the Apple Software in its entirety and without modifications, you must retain
  32.                 this notice and the following text and disclaimers in all such redistributions of
  33.                 the Apple Software.  Neither the name, trademarks, service marks or logos of
  34.                 Apple Computer, Inc. may be used to endorse or promote products derived from the
  35.                 Apple Software without specific prior written permission from Apple.  Except as
  36.                 expressly stated in this notice, no other rights or licenses, express or implied,
  37.                 are granted by Apple herein, including but not limited to any patent rights that
  38.                 may be infringed by your derivative works or by other works in which the Apple
  39.                 Software may be incorporated.
  40.  
  41.                 The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO
  42.                 WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED
  43.                 WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  44.                 PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN
  45.                 COMBINATION WITH YOUR PRODUCTS.
  46.  
  47.                 IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR
  48.                 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
  49.                 GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  50.                 ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION
  51.                 OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF CONTRACT, TORT
  52.                 (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN
  53.                 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  54. */
  55.  
  56. #define kVerboseErrors
  57. //#define kQuake3
  58.  
  59. // system includes ----------------------------------------------------------
  60.  
  61. #ifdef kQuake3
  62. typedef int sysEventType_t;    // FIXME...
  63. #endif
  64.  
  65. #include <MacTypes.h>
  66.  
  67. #include <stdio.h>
  68.  
  69.  
  70. // project includes ---------------------------------------------------------
  71.  
  72. #include "SetupDSp.h"
  73.  
  74. #include "Error Handler.h"
  75.  
  76. #ifdef kQuake3
  77. #include "../renderer/tr_local.h"
  78. #include "mac_local.h"
  79. #endif
  80.  
  81.  
  82. // globals (internal/private) -----------------------------------------------
  83.  
  84.  
  85. // prototypes (internal/private) --------------------------------------------
  86.  
  87. static void CStrToPStr (StringPtr outString, const char *inString);
  88.  
  89.  
  90. // functions (internal/private) ---------------------------------------------
  91.  
  92. // Copy C string to Pascal string
  93.  
  94. static void CStrToPStr (StringPtr outString, const char *inString)
  95. {    
  96.     unsigned char x = 0;
  97.     do
  98.         *(((char*)outString) + x) = *(inString + x++);
  99.     while ((*(inString + x) != 0)  && (x < 256));
  100.     *((char*)outString) = (char) x;                                    
  101. }
  102.  
  103. #pragma mark -
  104. // --------------------------------------------------------------------------
  105.  
  106. // central error reporting
  107.  
  108. void ReportErrorNum (char * strError, long numError)
  109. {
  110.     char errMsgCStr [256];
  111.     Str255 strErr = "\p";
  112.     
  113.     sprintf (errMsgCStr, "%s %d\n", strError, numError); 
  114.  
  115.     // out as debug string
  116. #ifdef kVerboseErrors
  117.     #ifdef kQuake3
  118.         ri.Printf( PRINT_ALL, errMsgCStr);
  119.     #else
  120.         // ensure we are faded in
  121.         if (gDSpStarted)
  122.             DSpContext_CustomFadeGammaIn (NULL, NULL, 0);
  123.         CStrToPStr (strErr, errMsgCStr);
  124.         DebugStr (strErr);
  125.     #endif // kQuake3
  126. #endif // kVerboseErrors
  127. }
  128.  
  129. // --------------------------------------------------------------------------
  130.  
  131. void ReportError (char * strError)
  132. {
  133.     char errMsgCStr [256];
  134.     Str255 strErr = "\p";
  135.  
  136.     sprintf (errMsgCStr, "%s\n", strError); 
  137.  
  138.     // out as debug string
  139. #ifdef kVerboseErrors
  140.     #ifdef kQuake3
  141.         ri.Printf( PRINT_ALL, errMsgCStr);
  142.     #else
  143.         // ensure we are faded in
  144.         if (gDSpStarted)
  145.             DSpContext_CustomFadeGammaIn (NULL, NULL, 0);
  146.         CStrToPStr (strErr, errMsgCStr);
  147.         DebugStr (strErr);
  148.     #endif //  kQuake3
  149. #endif // kVerboseErrors
  150. }
  151.  
  152. //-----------------------------------------------------------------------------------------------------------------------
  153.  
  154. OSStatus DSpReportError (OSStatus error)
  155. {
  156.     switch (error)
  157.     {
  158.         case noErr:
  159.             break;
  160.         case kDSpNotInitializedErr:
  161.             ReportError ("DSp Error: Not initialized");
  162.             break;
  163.         case kDSpSystemSWTooOldErr:
  164.             ReportError ("DSp Error: system Software too old");
  165.             break;
  166.         case kDSpInvalidContextErr:
  167.             ReportError ("DSp Error: Invalid context");
  168.             break;
  169.         case kDSpInvalidAttributesErr:
  170.             ReportError ("DSp Error: Invalid attributes");
  171.             break;
  172.         case kDSpContextAlreadyReservedErr:
  173.             ReportError ("DSp Error: Context already reserved");
  174.             break;
  175.         case kDSpContextNotReservedErr:
  176.             ReportError ("DSp Error: Context not reserved");
  177.             break;
  178.         case kDSpContextNotFoundErr:
  179.             ReportError ("DSp Error: Context not found");
  180.             break;
  181.         case kDSpFrameRateNotReadyErr:
  182.             ReportError ("DSp Error: Frame rate not ready");
  183.             break;
  184.         case kDSpConfirmSwitchWarning:
  185. //            ReportError ("DSp Warning: Must confirm switch"); // removed since it is just a warning, add back for debugging
  186.             return 0; // don't want to fail on this warning
  187.             break;
  188.         case kDSpInternalErr:
  189.             ReportError ("DSp Error: Internal error");
  190.             break;
  191.         case kDSpStereoContextErr:
  192.             ReportError ("DSp Error: Stereo context");
  193.             break;
  194.     }
  195.     return error;
  196. }
  197.  
  198. //-----------------------------------------------------------------------------------------------------------------------
  199.  
  200. // if error dump agl errors to debugger string, return error
  201.  
  202. GLenum aglReportError (void)
  203. {
  204.     GLenum err = aglGetError();
  205.     if (AGL_NO_ERROR != err)
  206.         ReportError ((char *)aglErrorString(err));
  207.     return err;
  208. }
  209.